package com.weiyi.portal.modules.pms.service.impl;

import com.weiyi.common.common.service.RedisService;
import com.weiyi.portal.modules.pms.model.PmsProduct;
import com.weiyi.portal.modules.pms.service.PmsProductCacheService;
import com.weiyi.portal.modules.pms.service.PmsProductService;
import com.weiyi.portal.modules.ums.mapper.UmsMemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 后台用户缓存管理Service实现类
 * Created by macro on 2020/3/13.
 */
@Service
public class PmsProductCacheServiceImpl implements PmsProductCacheService {
    @Autowired
    private PmsProductService pmsProductService;
    @Autowired
    private RedisService redisService;


    @Autowired
    private UmsMemberMapper memberMapper;
    @Value("${redis.database}")
    private String REDIS_DATABASE;
    @Value("${redis.expire.common}")
    private Long REDIS_EXPIRE;
    @Value("${redis.key.product}")
    private String REDIS_KEY_ADMIN;

    @Override
    public void delProduct(Long proId) {
        PmsProduct product = pmsProductService.getById(proId);
        if (product != null) {
            String key = REDIS_DATABASE + ":" + REDIS_KEY_ADMIN + ":" + product.getName();
            redisService.del(key);
        }
    }



    @Override
    public PmsProduct getProduct(String name) {
        String key = REDIS_DATABASE + ":" + REDIS_KEY_ADMIN + ":" + name;
        return (PmsProduct) redisService.get(key);
    }

    @Override
    public void setProduct(PmsProduct product) {
        String key = REDIS_DATABASE + ":" + REDIS_KEY_ADMIN + ":" + product.getName();
        redisService.set(key, product, REDIS_EXPIRE);
    }


}
